﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Media;

namespace AlarmManagePlatform.Forms
{
    public partial class IVShowForm : RelationsLMP.Control.Form.MetroDemoForms
    {
        private IVShowForm()
        {
            InitializeComponent();

            btnPlay.Click += BtnPlay_Click;
            labAlarm.ForeColor = Color.Red;
        }

        public IVShowForm(string _Value):this()
        {
            labValue.Text = _Value;
        }

        private string voiceFile;

        public string VoiceFile
        {
            get { return voiceFile; }
            set
            {
                voiceFile = value;
                if (string.IsNullOrEmpty(voiceFile))
                {
                    pVoice.Enabled = true;
                }
                else
                {
                    pVoice.Enabled = true;
                   // btnPlay.Click += BtnPlay_Click;
                }
            }
        }

        public Stream Stream { get; set; }

        private void BtnPlay_Click(object sender, EventArgs e)
        {
            //System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Stream);
            //sp.Play();

            SoundPlayer player = new SoundPlayer();
            Stream.Position = 0;
            player.Stream = null;
            player.Stream = Stream;
            player.Load();
            player.Play();
        }

        private Bitmap bitmap;
        
        public Bitmap Bitmap
        {
            get { return bitmap; }
            set
            {
                bitmap = value;

                if (value != null)
                {
                    labAlarm.Visible = false;
                    pImage.BackgroundImage = value;
                    if (pImage.Width < value.Width || pImage.Height < value.Height)
                        pImage.BackgroundImageLayout = ImageLayout.Stretch;
                    else
                        pImage.BackgroundImageLayout = ImageLayout.Center;
                }
                else
                {
                    labAlarm.Visible = true;
                    labAlarm.Dock = DockStyle.Fill;
                    labAlarm.AutoSize = false;
                    labAlarm.TextAlign = ContentAlignment.MiddleCenter;
                }
            }
        }

    }
}
